package com.cn.ycy.aop.annation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Order(2)
public class AopCustomAspect {

  Logger logger = LoggerFactory.getLogger(AopCustomAspect.class);

//	也可以使用自己的自定义注解做切面
  @Pointcut("execution(public * com.cn.ycy.aop.annation.ServiceImpl.doWork(..))")
  public void ad() {
  }

  @Before(value = "ad()")
  public void before() {
    logger.warn("before 0 ....");
  }

  @Before(value = "ad()")
  public void before2() {
    //问题：这个通知也是before，作用在同一个方法上，那么 上面的通知先执行还是下面的通知先执行？
    //答案：按照运行结果来看 好像是按照了方法的 名称的自然排序 作为执行顺序
    logger.warn("复习一下....");
  }

  @Around(value = "ad()")
  public void zaround(ProceedingJoinPoint joinPoint) throws Throwable {
    logger.warn("around 1 ....");
    joinPoint.proceed();
    logger.warn("around 2 ...");
  }

  @After(value = "ad()")
  public void after() throws Throwable {
    logger.warn("@After....");
  }

  @AfterReturning(value = "ad()")
  public void AfterReturning() throws Throwable {
    logger.warn("@AfterReturning....");

  }


}
